package com.yitongmao.util;

import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by xiaowei on 2017/1/5.
 */

public class ComparatorDate {
    public static final String TAG = "ComparatorDate";


    SimpleDateFormat format = new SimpleDateFormat("yyyy/M/d H:mm:ss");

    public int compare(Object obj1, Object obj2) {
        LivingListBean.ListEntity t1 = (LivingListBean.ListEntity) obj1;
        LivingListBean.ListEntity t2 = (LivingListBean.ListEntity) obj2;
        //   return t1.getTradetime().compareTo(t2.getTradetime());  // 时间格式不好，不然可以直接这样比较
        Date d1, d2;
        try {
            d1 = format.parse(t1.getStartTime());
            d2 = format.parse(t2.getStartTime());
        } catch (ParseException e) {
            // 解析出错，则不进行排序
            Log.e(TAG, "ComparatorDate--compare--SimpleDateFormat.parse--error");
            return 0;
        }
        if (d1.before(d2)) {
            return 1;
        } else {
            return -1;
        }
    }
}
